home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Technotools
/
Technotools (Chestnut CD-ROM)(1993).ISO
/
lang_c
/
cuj9204
/
1004017a
< prev
next >
Wrap
Text File
|
1992-06-02
|
507b
|
25 lines
#include <stdlib.h>
#include <string.h>
typedef enum {FLOAT, INTEGER} Code;
typedef struct {
char *s;
Code code;
} Entry;
Entry symtab[] = {
{"float", FLOAT},
{"integer", INTEGER}}
static int cmp(const void *ck, const void *ce)
{ /* compare key to table element */
return (strcmp((const char *)ck, ((Entry *)ce)->s));
}
Entry *lookup(char *key)
{ /* lookup key in table */
return (bsearch(key, symtab,
sizeof symtab / sizeof symtab[0],
sizeof symtab[0], &cmp));
}